package com.kgc.ebookmanagement2.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.ebookmanagement2.mapper.Ebook_EntryMapper;
import com.kgc.ebookmanagement2.pojo.Ebook_Entry;
import com.kgc.ebookmanagement2.pojo.Ebook_EntryExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Ebook_EntryServiceImpl implements Ebook_EntryService {

    @Resource
    Ebook_EntryMapper entryMapper;

    @Override
    public PageInfo<Ebook_Entry> getSelect(Integer pageNum, Integer pageSize, Integer categoryId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Ebook_Entry> entryList;
        if(categoryId!=0){
            Ebook_EntryExample example=new Ebook_EntryExample();
            Ebook_EntryExample.Criteria criteria=example.createCriteria();
            criteria.andCategoryidEqualTo(categoryId);
            entryList=entryMapper.selectByExample(example);
        }else{
            entryList=entryMapper.selectByExample(null);
        }

        PageInfo<Ebook_Entry> pageInfo=new PageInfo<>(entryList);
        return pageInfo;
    }

    @Override
    public Integer add(Ebook_Entry entry) {
        int i=entryMapper.insert(entry);
        return 1;
    }

    @Override
    public Ebook_Entry selectById(Integer id) {
        Ebook_Entry entry=entryMapper.selectByPrimaryKey(id);
        return entry;
    }

    @Override
    public Integer update(Ebook_Entry entry) {
        int i=entryMapper.updateByPrimaryKeySelective(entry);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=entryMapper.deleteByPrimaryKey(id);
        return i;
    }
}